<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var findLeastNumOfUniqueInts = function (arr, k) {
      let obj = {}
      arr.forEach((item) => {
        if (obj[item]) {
          obj[item] += 1
        } else {
          obj[item] = 1
        }
      })
      arr.sort((a, b) => {
        return obj[a] - obj[b] || a - b
      })
      arr.splice(0, k)
      return Array.from(new Set(arr)).length
    };
    console.log(findLeastNumOfUniqueInts([5, 5, 4], 1));
  </script>
</body>

</html>